package com.rsxy.service.controller;



import com.rsxy.service.tools.QiNiuUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.log4j.Log4j2;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
@Log4j2
@ResponseBody
@RequestMapping("/qiniu")
@Api(tags= "七牛云存储接口")
public class QiNiuController {
    @ApiOperation(value = "获取token",notes = "测试数据")
    @RequestMapping(method = RequestMethod.GET,value = "/getToken")
    public Map<String, String> getToken() throws IOException {
        String bucket = "rsxy_image";
        Map<String, String> map = QiNiuUtil.getToken(bucket);
        return map;
    }
    @ApiOperation(value = "从七牛云删除文件",notes = "测试数据")
    @RequestMapping(method = RequestMethod.GET,value = "/deleteFile")
    public Map<String, String> deleteFile(@RequestBody String key) throws IOException {
        String bucket = "rsxy_image";
         Map<String, String> map=new HashMap<>();
         if (QiNiuUtil.deleteFile(bucket,key)){
             map.put("msg","success");
         }else {
             map.put("msg","erro");
         }
        return map;
    }
}
